package com.sicau.controller;

import com.github.pagehelper.PageInfo;
import com.sicau.entity.Student;
import com.sicau.entity.User;
import com.sicau.service.IDocService;
import com.sicau.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
	@Autowired
	private LoginService loginService;
	@Autowired
	private IDocService iDocService;

	@RequestMapping("/login")
	public String login(String account,String password) {
		System.out.println(account);
		String result = loginService.login(account,password);
		System.out.println(result);
		return result;
	}
	@RequestMapping("/insert")
	public String insert(String id,String name,String password) {
			User user = new User();
			user.setId(id);
			user.setName(name);
			user.setPassword(password);
			int result = loginService.insert(user);
			if(result == 0){
				return "error";
			}
		return "welcome";
	}
	@RequestMapping("/select")
	public ModelAndView select(String id) {
		User user = loginService.select(id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("user",user);
		modelAndView.setViewName("welcome");
		return modelAndView;
	}
	@RequestMapping("/test")
	public ModelAndView test(){
		PageInfo<Student> pageInfo = iDocService.selectDocByPage1(2,10);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("pageInfo",pageInfo);
		modelAndView.setViewName("welcome");
		return modelAndView;
	}
}
